package com.xushimu.controller;

import com.xushimu.domain.Product;
import com.xushimu.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;


@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;

    /**
     * @author 徐世牧
     * @date 2019/7/14 11:50
     * @description :查询所有产品的方法
     */
    @RequestMapping("/findAll")
    public String findAll(Model model) throws Exception {
        System.out.println("这里是findall方法~");
        List<Product> list = productService.findAll();
        System.out.println(list);
        model.addAttribute("products",list);
        return "product-list";
    }
    /**
     * @author 徐世牧
     * @date 2019/7/14 11:50
     * @description ：添加页面的跳转方法，指定get请求跳转到，添加数据的页面
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(){
        return "product-add";
    }
    /**
     * @author 徐世牧
     * @date 2019/7/14 21:24
     * @description :重定向到保存所有的方法
     */
    public String add(Product product){

        return "redirect:/product/findAll";
    }
}
